<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>主页</el-breadcrumb-item>
      <el-breadcrumb-item style="font-weight: 700; color: #515a6e"
        >志愿者审核</el-breadcrumb-item
      ><br />
      <el-card class="box-card">
        <el-row>
          <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="" class="el-form-items">
              <el-select v-model="formInline.region" placeholder="活动区域">
                <el-option label="济南市" value="shanghai"></el-option>
                <el-option label="青岛市" value="beijing"></el-option>
                <el-option label="淄博市" value="beijing"></el-option>
                <el-option label="枣庄市" value="beijing"></el-option>
                <el-option label="东营市" value="beijing"></el-option>
                <el-option label="烟台市" value="beijing"></el-option>
                <el-option label="潍坊市" value="beijing"></el-option>
                <el-option label="济宁市" value="beijing"></el-option>
                <el-option label="泰安市" value="beijing"></el-option>
                <el-option label="威海市" value="beijing"></el-option>
                <el-option label="日照市" value="beijing"></el-option>
                <el-option label="临沂市" value="beijing"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="" class="el-form-items">
              <el-select v-model="formInline.region" placeholder="请选择">
                <el-option label="请选择" value="shanghai"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="" class="el-form-items">
              <el-button
                type="primary"
                @click="dialogFormVisible = true"
                class="loves"
                >批量审核</el-button
              >
            </el-form-item>

            <!-- <el-button type="primary" @click="dialogFormVisible = true" class="loves"
              >上传视频</el-button
            > -->
            <el-form-item label="">
              <el-input placeholder="搜索关键字" v-model="search"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="getLista">搜索</el-button>
            </el-form-item>
          </el-form>
        </el-row>
        <div class="form">
          <el-table
            border
            ref="multipleTable"
            :data="tableData"
            :header-cell-style="getRowClass"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column prop="name" label="用户名" width="180">
            </el-table-column>
            <el-table-column prop="mobile" label="手机号" width="180">
            </el-table-column>
            <el-table-column prop="" label="头像"> </el-table-column>
            <el-table-column prop="region" label="地区"> </el-table-column>
            <el-table-column prop="status" label="状态">
              <template slot-scope="scope">
                <span v-if="scope.row.status == 1">已通过</span>
                <span v-if="scope.row.status == 2">未通过</span>
              </template>
            </el-table-column>

            <el-table-column prop="utime" label="创建时间">
              <template slot-scope="scope">
                {{ getCtime(scope.row.ctime) }}
              </template>
            </el-table-column>
            <el-table-column prop="" label="是否为管理员">
              <template slot-scope="scope">
                <span v-if="scope.row.status == 0"
                  ><button class="statusup">是</button></span
                >
                <span v-if="scope.row.status == 1"
                  ><button class="statusdown">否</button></span
                >
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              align="center"
              label="操作"
              width="200"
            >
              <template slot-scope="alter">
                <el-button type="primary" size="small" icon="el-icon-search"
                  ><span>审核</span></el-button
                >
                <el-button
                  type="danger"
                  icon="el-icon-delete"
                  size="small"
                  @click="del(alter.row)"
                  ><span>删除</span>
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="100"
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </el-card>
    </el-breadcrumb>
  </div>
</template>

<script>
import { getLista, delList } from "@/api/shenhe.js";
export default {
  name: "WishView",
  data() {
    return {
      page: 0,
      size: 10,
      tableData: [],
      total: 10,
      search: "",
      formInline: {
        user: "",
        region: "",
      },
    };
  },
  created() {
    this.getLista();
  },
  watch: {
    search(search) {
      this.getLista(search);
      if (!search) {
        this.videos;
        return;
      }
    },
  },
  methods: {
    async getLista() {
      const ruleForm = {
        _orderd: "ctime",
        _page: this.page,
        _size: this.size,
      };
      if (this.search) {
        ruleForm._search = this.search;
        const res = await getLista(ruleForm);
        if (res.code === 1) {
          console.log(res);
          this.tableData = res.list;
          this.total = res.pager.total;
        }
      }
      const res = await getLista(ruleForm);
      if (res.code === 1) {
        console.log(res);
        this.tableData = res.list;
        this.total = res.pager.total;
      }
    },
      //设置表头背景颜色
    getRowClass() {
      return "background: #F8F8F9;border:#black;color:515A6E;";
    },

    // 处理时间
    getCtime(cTime) {
      const time = Date.parse(cTime);
      var date = new Date(time);
      var YY = date.getFullYear() + "-";
      var MM =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      var hh =
        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
      var mm =
        (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
        ":";
      var ss =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      return YY + MM + DD + " " + hh + mm + ss;
    },
    handleSizeChange(page) {
      this.size = page;
      this.getLista();
    },
    handleCurrentChange(size) {
      this.page = size;
      this.getLista();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //删除
    async del(data) {
      let r = confirm("你确定要删除该用户吗");
      if (r) {
        const res = await delList({ id: data.id });
        if (res.code === 1) {
          alert("删除成功");
        }
        this.getLista();
      } else {
        alert("取消删除");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.el-breadcrumb .el-card {
  margin-top: 30px;
  // height: 100%;
}

.el-card .el-row .el-button {
  float: left;
}

.el-card .el-row .el-form {
  float: right;
}

.block {
  margin-top: 20px;
}
el-button span {
  float: left;
}
.el-form-items {
  position: relative;
  right: 370px;
}
.statusup {
  border-radius: 3px;
  font-size: 12px;
  vertical-align: middle;
  opacity: 1;

  margin: 2px 4px 2px 0;
  width: 37.6px;
  height: 32px;
  background-color: #91d5ff;
}
.statusdown {
  border-radius: 3px;
  font-size: 12px;
  vertical-align: middle;
  opacity: 1;

  margin: 2px 4px 2px 0;
  width: 37.6px;
  height: 32px;
  background-color: #e8eaec;
}
</style>